var app = getApp()
let hide_good_box = true;
function dotMove(e){
    // hide_good_box为true，good_box正在运动
    if (hide_good_box) return;
    //当前点击位置的x，y坐标
    this.finger = {};
    var topPoint = {};
    this.finger['x'] = e.touches["0"].clientX;
    this.finger['y'] = e.touches["0"].clientY - 20;
    // 如果点击的位置小于购物车的位置，那么就让topPoint的y值等于点击的位置的y值，否则就让topPoint的y值等于购物车的y值
    if (this.finger['y'] < this.busPos['y']) {
        topPoint['y'] = this.finger['y'] - 150;
    } else {
        topPoint['y'] = this.busPos['y'] - 150;
    }
    topPoint['x'] = (this.finger['x'] + this.busPos['x']) / 2;
    this.linePos = app.bezier([this.finger, topPoint, this.busPos], 30);
    this.startAnimation(e);
};
function startAnimation(e){
    var index = 0,
        that = this,
        bezier_points = that.linePos['bezier_points'];
    this.setData({
        hide_good_box: false,
        bus_x: that.finger['x'],
        bus_y: that.finger['y']
    })
    this.timer = setInterval(function() {
        index++;
        that.setData({
            bus_x: bezier_points[index]['x'],
            bus_y: bezier_points[index]['y']
        })
        if (index >= 28) {
            clearInterval(that.timer);
            that.setData({
                hide_good_box: true,
                hideCount: false,
                count: that.data.count += 1
            })
        }
    }, 33); 
}
export default {
    dotMove,
    startAnimation
}